package gapidt.plugin.dialogs;

import gapidt.analysis.DesignProblem;
import gapidt.common.Locale;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class DesignProblemInfoDialog extends TitleAreaDialog {
	
	protected DesignProblem<?> designProblem; 
	
	public DesignProblemInfoDialog(Shell shell, DesignProblem<?> designProblem) {
		super(shell);
		this.setHelpAvailable(false); //Deshabilitar ayuda
		this.designProblem = designProblem;
	}
	
	/**
	 * Crear contenidos del dialogo
	 */
	protected Control createContents(Composite parent) {
		Control contents = super.createContents(parent);

		// Set the title and title image
		setTitle(designProblem.getName());
		
	    // Set the message
		setMessage(Locale.getMessage("design_problem_dialog_title_message"), IMessageProvider.INFORMATION);
		
	    return contents;
	}
	
	 protected Control createDialogArea(Composite parent) {
		 Composite composite = (Composite) super.createDialogArea(parent);
		 
		 // Create a table
		 Table table = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER);
		 GridData gridData = new GridData(GridData.FILL_BOTH);
		 gridData.widthHint = 300;
		 table.setLayoutData(gridData);
		 table.setLinesVisible(false);

		 // Crear columnas
		 TableColumn c1 = new TableColumn(table, SWT.LEFT | SWT.BOLD);
		 TableColumn c2 = new TableColumn(table, SWT.LEFT);
		 
		 table.setHeaderVisible(false);

		 // Agregar datos
		 TableItem item = new TableItem(table, SWT.NONE);
		 item.setText(0, Locale.getMessage("problem"));
		 item.setText(1, designProblem.getProblemDescription());
		 
		 item = new TableItem(table, SWT.NONE);
		 item.setText(0, Locale.getMessage("solution"));
		 item.setText(1, designProblem.getSolutionDescription());

		 if(designProblem.getTemplateBinding("class") != null){
			 item = new TableItem(table, SWT.NONE);
			 item.setText(0, Locale.getMessage("class"));
			 item.setText(1, designProblem.getTemplateBinding("class"));
		 }

		 if(designProblem.getTemplateBinding("method") != null){
			 item = new TableItem(table, SWT.NONE);
			 item.setText(0, Locale.getMessage("method"));
			 item.setText(1, designProblem.getTemplateBinding("method"));
		 }
		 
		 if(designProblem.getTemplateBinding("parameter") != null){
			 item = new TableItem(table, SWT.NONE);
			 item.setText(0, Locale.getMessage("parameter"));
			 item.setText(1, designProblem.getTemplateBinding("parameter"));
		 }
		 
		 if(designProblem.getTemplateBinding("parameterType") != null){
			 item = new TableItem(table, SWT.NONE);
			 item.setText(0, Locale.getMessage("parameterType"));
			 item.setText(1, designProblem.getTemplateBinding("parameterType"));
		 }
		 
		 if(designProblem.getTemplateBinding("returnType") != null){
			 item = new TableItem(table, SWT.NONE);
			 item.setText(0, Locale.getMessage("returnType"));
			 item.setText(1, designProblem.getTemplateBinding("returnType"));
		 }
		 c1.pack();
		 c2.pack();

		 return composite;
	 }
	
	/**
	 * Crear botones (solo OK)
	 */
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
	}

}
